package com.wzc.hc.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wzc.hc.entity.po.InvoiceTitle;
import com.wzc.hc.service.InvoiceTitleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/*
@author:甲方
@date:2025/3/518:23
*/
@RestController
@RequestMapping("/invoiceTitle")
public class InvoiceTitleController {

    @Autowired
    private InvoiceTitleService invoiceTitleService;

    // 获取所有发票抬头
    @GetMapping
    public List<InvoiceTitle> getAllInvoiceTitles() {
        return invoiceTitleService.list();
    }

    // 根据id获取发票抬头
    @GetMapping("/{id}")
    public InvoiceTitle getInvoiceTitleById(@PathVariable String id) {
        return invoiceTitleService.getById(id);
    }

    // 添加发票抬头
    @PostMapping
    public boolean addInvoiceTitle(@RequestBody InvoiceTitle invoiceTitle) {
        return invoiceTitleService.save(invoiceTitle);
    }

    // 更新发票抬头
    @PutMapping("/{id}")
    public boolean updateInvoiceTitle(@PathVariable String id, @RequestBody InvoiceTitle invoiceTitle) {
        invoiceTitle.setSiteId(id);
        return invoiceTitleService.updateById(invoiceTitle);
    }

    // 删除发票抬头
    @DeleteMapping("/{id}")
    public boolean deleteInvoiceTitle(@PathVariable String id) {
        return invoiceTitleService.removeById(id);
    }

    // 分页查询发票抬头
    @GetMapping("/page")
    public Page<InvoiceTitle> getInvoiceTitlesByPage(@RequestParam int current, @RequestParam int size) {
        Page<InvoiceTitle> page = new Page<>(current, size);
        return invoiceTitleService.page(page);
    }

    // 根据楼栋房屋和业主名称获取发票抬头
    @GetMapping("/byBuildingAndOwnerName")
    public List<InvoiceTitle> getInvoiceTitlesByBuildingAndOwnerName(
            @RequestParam String building,
            @RequestParam String ownerName) {
        return invoiceTitleService.getInvoiceTitlesByBuildingAndOwnerName(building, ownerName);
    }
}

